package com.chery.media.ui.play.usb

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.chery.media.R
import com.chery.media.network.model.MusicBean

/**
 * 热门音乐列表
 */
class UsbAdapter: BaseQuickAdapter<MusicBean, BaseViewHolder>(R.layout.item_music) {

    var selectIndex = 0

    override fun convert(holder: BaseViewHolder, item: MusicBean) {
        holder.apply {
            setText(R.id.sortText, "${layoutPosition + 1}")
            val name = if (item.title.isNullOrEmpty()) item.playPath?.substring(item.playPath!!.lastIndexOf("/") + 1, item.playPath!!.lastIndexOf(".")) ?: "" else item.title
            setText(R.id.musicNameText, name)
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setSelect(index: Int) {
        this.selectIndex = index
        notifyDataSetChanged()
    }

}